package utilities.utilities_components;

import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.zkoss.zul.Messagebox;
import org.zkoss.zul.Window;
import org.zkoss.zul.Chart;
import org.zkoss.zul.SimplePieModel;

import utilities.Updatable;

public class PlainChart extends Window implements Updatable{
	private Chart pie;
	private SimplePieModel model;
	
	public PlainChart(){
		model = new SimplePieModel();
		
		pie = new Chart();
		pie.setModel( model );
		pie.setType( "pie" );
		pie.setThreeD( true );
		pie.setFgAlpha( 128 );
	}
	
	public void update( List data ){
		if( data == null ){
			try{
				new Messagebox().show( "更新失败!" );
			}catch( InterruptedException exception ){
				/*  Ignore  */
			}
			
			return;
		}
		
		model.clear();
		
		List keys = ( List )data.get( 0 );
		List values = ( List )data.get( 1 );
		Iterator keyIter = keys.iterator();
		Iterator valueIter = values.iterator();
		while( keyIter.hasNext() ){
			model.setValue( ( Comparable )keyIter.next(), ( Number )valueIter.next() );
		}
		return;
	}

	@Override
	public void setDisable(boolean disabled) {
		// TODO Auto-generated method stub
		
	}
}
